package com.molichuxing.services.infrastructure.convertor;

import com.molichuxing.services.business.dto.request.create.GoodsBaseCreateDto;
import com.molichuxing.services.business.dto.request.create.GoodsExclusiveCreateDto;
import com.molichuxing.services.business.dto.request.create.GoodsSubscribeCreateDto;
import com.molichuxing.services.business.dto.request.create.GoodsSubscribePackageCreateDto;
import com.molichuxing.services.infrastructure.bean.*;
import com.molichuxing.services.infrastructure.dto.response.*;
import com.molichuxing.services.property.GoodsMileageTypeEnum;
import com.molichuxing.services.property.GoodsPaymentTypeEnum;
import com.molichuxing.services.property.GoodsTransferFeeEnum;
import org.springframework.beans.BeanUtils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @create_date: 2019/4/3
 * @name:goods-service
 **/
public class Convert {
    /********************************************mybits-plus分页结果转换开始 *****************************/
    public static List<GoodsDto> toProductBeanDto(List<GoodsBean> beanList) {
        List<GoodsDto> dtoList = null;;
        if (beanList != null && beanList.size() > 0) {
            dtoList = new ArrayList<>();
            for (GoodsBean bean : beanList) {
                dtoList.add(toProductBeanDto(bean));
            }
        }

        return dtoList;
    }

    public static GoodsDto toProductBeanDto(GoodsBean bean) {
        GoodsDto beanDto = null;
        if (bean != null) {
            beanDto = new GoodsDto();
            BeanUtils.copyProperties(bean, beanDto);
            beanDto.setIsForbidSale(bean.getForbidSale());
        }
        return beanDto;
    }
    /********************************************mybits-plus分页结果转换结束 *****************************/

    /********************************************商品规格主要信息转换 开始 *****************************/
    public static List<GoodsSpecDto> toGoodsProductSpecBeanDto(List<GoodsSpecBean> beanList) {
        List<GoodsSpecDto> dtoList = null;;
        if (beanList != null && beanList.size() > 0) {
            dtoList = new ArrayList<>();
            for (GoodsSpecBean bean : beanList) {
                dtoList.add(toGoodsProductSpecBeanDto(bean));
            }
        }
        return dtoList;
    }

    public static GoodsSpecDto toGoodsProductSpecBeanDto(GoodsSpecBean bean) {
        GoodsSpecDto beanDto = null;
        if (bean != null) {
            beanDto = new GoodsSpecDto();
            BeanUtils.copyProperties(bean, beanDto);
        }
        return beanDto;
    }


    public static List<GoodsIntroduceDto> toGoodsIntroduceDto(List<GoodsIntroduceBean> beanList) {
        List<GoodsIntroduceDto> dtoList = null;;
        if (beanList != null && beanList.size() > 0) {
            dtoList = new ArrayList<>();
            for (GoodsIntroduceBean bean : beanList) {
                dtoList.add(toGoodsIntroduceDto(bean));
            }
        }
        return dtoList;
    }

    public static GoodsIntroduceDto toGoodsIntroduceDto(GoodsIntroduceBean bean) {
        GoodsIntroduceDto beanDto = null;
        if (bean != null) {
            beanDto = new GoodsIntroduceDto();
            BeanUtils.copyProperties(bean, beanDto);
        }
        return beanDto;
    }

    /********************************************商品规格主要信息转换 结束 *****************************/

    /********************************************商品配置规格主要信息转换 开始 *****************************/
    public static List<GoodsSpecConfigDto> toGoodsProductSpecConfigBeanDto(List<GoodsSpecConfigBean> beanList) {
        List<GoodsSpecConfigDto> dtoList = null;;
        if (beanList != null && beanList.size() > 0) {
            dtoList = new ArrayList<>();
            for (GoodsSpecConfigBean bean : beanList) {
                dtoList.add(toGoodsProductSpecConfigBeanDto(bean));
            }
        }
        return dtoList;
    }

    public static GoodsSpecConfigDto toGoodsProductSpecConfigBeanDto(GoodsSpecConfigBean bean) {
        GoodsSpecConfigDto beanDto = null;
        if (bean != null) {
            beanDto = new GoodsSpecConfigDto();
            BeanUtils.copyProperties(bean, beanDto);
        }
        return beanDto;
    }
    /********************************************商品配置规格主要信息转换 结束 *****************************/

    /********************************************订阅商品信息转换 开始 *****************************/
    public static List<GoodsSubscribeDto> toGoodsProductSubscribeDto(List<GoodsSubscribeBean> beanList) {
        List<GoodsSubscribeDto> dtoList = null;;
        if (beanList != null && beanList.size() > 0) {
            dtoList = new ArrayList<>();
            for (GoodsSubscribeBean bean : beanList) {
                dtoList.add(toGoodsProductSubscribeDto(bean));
            }
        }
        return dtoList;
    }

    public static GoodsSubscribeDto toGoodsProductSubscribeDto(GoodsSubscribeBean bean) {
        GoodsSubscribeDto beanDto = null;
        if (bean != null) {
            beanDto = new GoodsSubscribeDto();
            BeanUtils.copyProperties(bean, beanDto);
        }
        return beanDto;
    }

    public static List<GoodsSubscribeMileageDto> toGoodsProductSubscribeMileageDto(List<GoodsSubscribeMileageBean> beanList) {
        List<GoodsSubscribeMileageDto> dtoList = null;;
        if (beanList != null && beanList.size() > 0) {
            dtoList = new ArrayList<>();
            for (GoodsSubscribeMileageBean bean : beanList) {
                dtoList.add(toGoodsProductSubscribeMileageDto(bean));
            }
        }
        return dtoList;
    }

    public static GoodsSubscribeMileageDto toGoodsProductSubscribeMileageDto(GoodsSubscribeMileageBean bean) {
        GoodsSubscribeMileageDto beanDto = null;
        if (bean != null) {
            beanDto = new GoodsSubscribeMileageDto();
            BeanUtils.copyProperties(bean, beanDto);
        }
        return beanDto;
    }
    /********************************************订阅商品信息转换 结束 *****************************/


    /********************************************专属商品信息转换 开始 *****************************/
    public static List<GoodsExclusiveDto> toGoodsProductExclusiveDto(List<GoodsExclusiveBean> beanList) {
        List<GoodsExclusiveDto> dtoList = null;;
        if (beanList != null && beanList.size() > 0) {
            dtoList = new ArrayList<>();
            for (GoodsExclusiveBean bean : beanList) {
                dtoList.add(toGoodsProductExclusiveDto(bean));
            }
        }
        return dtoList;
    }

    public static GoodsExclusiveDto toGoodsProductExclusiveDto(GoodsExclusiveBean bean) {
        GoodsExclusiveDto beanDto = null;
        if (bean != null) {
            beanDto = new GoodsExclusiveDto();
            BeanUtils.copyProperties(bean, beanDto);
            beanDto.setExclusiveType(bean.getType());
        }
        return beanDto;
    }
    /********************************************专属商品信息转换 结束 *****************************/

    /********************************************添加商品信息转换 开始 *****************************/

    public static GoodsBean toGoodsProductBean(GoodsBaseCreateDto createDto) {
        GoodsBean goodsBean = new GoodsBean();
        BeanUtils.copyProperties(createDto, goodsBean);
        goodsBean.setType(createDto.getType().getValue());
        return goodsBean;
    }

    public static GoodsExclusiveBean toExclusiveGoodsProductBean(GoodsExclusiveCreateDto createDto) {
        GoodsExclusiveBean goodsProductBean = new GoodsExclusiveBean();
        BeanUtils.copyProperties(createDto, goodsProductBean);
        goodsProductBean.setPaymentType(createDto.getPaymentType().getValue());
        goodsProductBean.setType(createDto.getExclusiveType());
        if(createDto.getPaymentType().getValue() == GoodsPaymentTypeEnum.WHOLE_PARAGRAPH.getValue()) {
            goodsProductBean.setTransferFee(new BigDecimal(GoodsTransferFeeEnum.ALL.getName()));
        }else {
            if(createDto.getIsBuyBackSpecId()== 1){
                goodsProductBean.setTransferFee(new BigDecimal(GoodsTransferFeeEnum.BUY_BACK.getName()));
            }else {
                goodsProductBean.setTransferFee(new BigDecimal(GoodsTransferFeeEnum.NO_BUY_BACK.getName()));
            }
        }

        return goodsProductBean;
    }

    public static GoodsSubscribeBean toSubscribeGoodsProductBean(GoodsSubscribeCreateDto createDto) {
        GoodsSubscribeBean goodsProductBean = new GoodsSubscribeBean();
        BeanUtils.copyProperties(createDto, goodsProductBean);
        if(null != createDto.getGoodsPackage() && createDto.getGoodsPackage().size() > 0) {
            for(GoodsSubscribePackageCreateDto goodsSubscribePackageCreateDto : createDto.getGoodsPackage()) {
                if(GoodsMileageTypeEnum.BASE == goodsSubscribePackageCreateDto.getPackageType()) {
                    goodsProductBean.setBaseMileage(goodsSubscribePackageCreateDto.getMiles());
                    goodsProductBean.setBaseMileagePrice(goodsSubscribePackageCreateDto.getMilesPrice());
                    break;
                }
            }
        }
        goodsProductBean.setServiceFee(createDto.getServiceFee());
        goodsProductBean.setPaymentType(createDto.getPaymentType().getValue());
        return goodsProductBean;
    }
    /********************************************添加商品信息转换 结束 *****************************/

    /********************************************mybits-plus分页结果转换开始 *****************************/
    public static List<GoodsDealerDto> toGoodsProductDealerBeanDto(List<GoodsDealerBean> beanList) {
        List<GoodsDealerDto> dtoList = null;;
        if (beanList != null && beanList.size() > 0) {
            dtoList = new ArrayList<>();
            for (GoodsDealerBean bean : beanList) {
                dtoList.add(toGoodsProductDealerBeanDto(bean));
            }
        }

        return dtoList;
    }

    public static GoodsDealerDto toGoodsProductDealerBeanDto(GoodsDealerBean bean) {
        GoodsDealerDto beanDto = null;
        if (bean != null) {
            beanDto = new GoodsDealerDto();
            BeanUtils.copyProperties(bean, beanDto);
        }
        return beanDto;
    }
    /********************************************mybits-plus分页结果转换结束 *****************************/

    /********************************************商品属性信息转换 开始 *****************************/
    public static List<GoodsPropertyDto> toGoodsProductPropertyDto(List<GoodsPropertyBean> beanList) {
        List<GoodsPropertyDto> dtoList = null;;
        if (beanList != null && beanList.size() > 0) {
            dtoList = new ArrayList<>();
            for (GoodsPropertyBean bean : beanList) {
                dtoList.add(toGoodsProductPropertyDto(bean));
            }
        }
        return dtoList;
    }

    public static GoodsPropertyDto toGoodsProductPropertyDto(GoodsPropertyBean bean) {
        GoodsPropertyDto beanDto = null;
        if (bean != null) {
            beanDto = new GoodsPropertyDto();
            BeanUtils.copyProperties(bean, beanDto);
        }
        return beanDto;
    }
    /********************************************专属商品信息转换 结束 *****************************/
}
